from django.db import models
from django.contrib.auth.models import AbstractUser
from datetime import datetime

GENER_CHOICES = (
    ('male', '男'),
    ('femalc', '女')
)


# 公共继承的模型，含有继承该模型的实体的生成日期
class BaseModel(models.Model):
    add_time = models.DateTimeField(default=datetime.now,
                                    verbose_name='添加时间')  # 不要写成 default=datetime.now(),这样该实体生成的时间会不准

    class Meta:
        abstract = True  # 防止生成表


class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50, verbose_name='昵称', default='')
    birthday = models.DateField(verbose_name='生日', null=True, blank=True)
    gender = models.CharField(verbose_name='性别', choices=GENER_CHOICES, max_length=6)
    address = models.CharField(max_length=100, verbose_name='地址', null=True, blank=True)
    mobile = models.CharField(max_length=11, verbose_name='手机号码')  # unique=True:不能重复
    image = models.ImageField(upload_to='head_image/%Y/%m/%d', default='default.jpg', verbose_name='头像')

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        if self.nick_name:
            return self.nick_name
        else:
            return self.username
